package com.example.tests;

import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;

import org.testng.annotations.Test;

import com.example.utils.SortedListOf;

public class GroupRemovalTests extends TestBase {
	
	@Test
	public void deleteSomeGroup() {
	    
	   	// model
		SortedListOf<GroupData>  groupListFromModel = app.getModel().getGroups();
		
		// Old Group list from DB
		SortedListOf<GroupData> oldGroupListFromDB = app.getGroupHelper().getGroupsFromCache();
		
		// get Group Index to remove
		int index = getRandomIndex(groupListFromModel.size());
		
		//perform actions
		app.getGroupHelper().deleteGroup(index);
	    
	    // save new state
		SortedListOf<GroupData>  newGroupListFromUI = app.getGroupHelper().getUiGroups();
		
		SortedListOf<GroupData>  newGroupListFromDB = app.getGroupHelper().getGroupsFromCache();
		
	    // compare states
	    assertThat(newGroupListFromUI, equalTo(groupListFromModel));
	    assertThat(newGroupListFromUI, equalTo(newGroupListFromDB));
	    assertThat(newGroupListFromDB, equalTo(oldGroupListFromDB.without(index)));
	}
}
